fn main() {
    let mut s = String::from("Let's play a game");
    let word = first_word(&s);
    // s.clear();
    // if ```s.clear()``` statement is here, compiling will result in an error
    // because s is not mutable as this time
    println!("{}", word);
    s.clear();

    let e = "hello world";
    let fw = f_word(&e);
    println!("{}", fw);

    let st = String::from("Today is Friday");
    let first = f_word(&st);
    println!("{}", first);

    let ano = f_word("How are you");
    println!("{}", ano);
}

fn first_word(s: &String) -> &str {
    let bs = s.as_bytes();
    for (i, &item) in bs.iter().enumerate() {
        if item == b' ' {
            return &s[..i];
        }
    }

    &s[..]
}

fn f_word(s: &str)->&str{
    let bs = s.as_bytes();
    for (i, &item) in bs.iter().enumerate() {
        if item == b' ' {
            return &s[..i];
        }
    }

    &s[..]
}